home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 276-300 / 288 / scripit / plot.script < prev    next >
Text File  |  1995-03-14  |  4KB  |  120 lines

  1. ;; Draw a function of form y = f(x) where all arguments are from the command
  2. ;; line in the following format:
  3. ;; function, startx, endx, scalex, scaley
  4. ;; function is in the format  "f(#x)"  ex:  "#x^2-4*#x" for x^2-4x
  5.  
  6. ;; Version 2.0 By Brian J. Bartlett (CIS 72037,570)
  7.  
  8. ;; try running it like this:          scripit scriptname "func" 0 20 1 1
  9. ;; or, to use the default formula:    scripit scriptname "" 0 20 1 1
  10. ;; To see a debug of the process try: 
  11. ;;                    scripit >ram:dump -d scriptname "" 0 20 1 1
  12. ;; then have a look at ram:dump.
  13. ;;
  14. ;;      USE CONTROL-LEFT MOUSE BUTTON TO BREAK OUT!!!
  15. ;;       unless you like waiting for 10 minutes for the script to end
  16.  
  17. begin
  18.  
  19. ;;Con Open "ram:dump"    ;Debugging option
  20. ;;Verbose Full
  21.  
  22. if #argcount  < 5             ;Did user supply enough args?
  23.     GoSub Complain            ;Complain bitterly (Show usuage and quit)
  24.     end
  25. endif
  26.  
  27. if $arg[1]                    ;Did user supply a forumla?
  28.     Let $Funct  = $arg[1]     ;Yes, copy it into $Funct
  29. else
  30.     Let $Funct  = "(#x^2-8*#x)"   ;No, copy default formula into $Funct
  31. endif
  32.  
  33. #startx = $arg[2]             ;Get all user args.
  34. #endx   = $arg[3]
  35. #scalex = $arg[4]
  36. #scaley = $arg[5]
  37.  
  38. ;; Now that the assigns are done, get a window
  39. #width  = #Scr.width
  40. If #width < 44
  41.     Con Echo "Screen too slim"
  42.     End
  43. Endif
  44.  
  45. #height = #Scr.height
  46. If #height < 44
  47.     Con Echo "Screen to short"
  48.     End
  49. Endif
  50.  
  51. $Con   ?= "CON:0/0/" #width "/" #height "/Plot" 
  52. Con Open $Con
  53.  
  54. S Window Plot                   ;Select plotting window
  55. W Front                         ;Bring it to the front
  56.  
  57. #middlex = #width/2             ;Calculate middle of screen width
  58. #middley = #height/2            ;Calculate middle of screen height
  59. #bottom  = #height - 11         ;Calculate right edge
  60. #right   = #width - 11          ;Calculate bottom edge
  61.  
  62. Gfx Clear                       ;Clear the borders
  63. Gfx Savemode 0                  ;Save previous modes
  64. Gfx Pen 1,0,JAM1                ;Set pen for drawing Axes
  65. Gfx Box #middlex,11,#middlex,#bottom    ;Draw Axes
  66. Gfx Box 11,#middley,#right,#middley     ;Draw Axes
  67. Gfx move 10,10                  ;Move pen
  68. Gfx text "Scripit Plotter"      ;Label the Window
  69. Gfx Pen 3,1,JAM1                ;Set pen for plotting function
  70.  
  71. ;;Now start the loop, plotting points as we find them
  72. #x = #startx                    ;Set starting point
  73. While #x <= #endx               ;Loop until done
  74.     Let #pointx = ((#x/#scalex)+(#Width/2))     ;Scale the drawing point
  75.     If #pointx < 10             ;Make sure it's not off the left edge
  76.         Goto skip               ;If it is, skip it
  77.     endif
  78.     If #pointx > (#Width-10)    ;Make sure it's not off the right edge
  79.         Goto skip               ;If it is, skip it
  80.     endif
  81.     Let #y = $Funct             ;Calculate y co-ordinate
  82.     Let #pointy = ((#Height/2)-(#y/#scaley))    ;Scale it
  83.     If #pointy < 10             ;Make sure it's not off the top edge
  84.        Goto skip                ;If it is, skip it
  85.     endif
  86.     If #pointy > (#Height-10)   ;Make sure it's not off the bottom edge
  87.         Goto skip               ;If it is, skip it
  88.     endif
  89.     Gfx Pixel #pointx, #pointy  ;Now plot it on the provided window
  90. Skip:                  
  91.     #x = #x+1                   ;Increment x for next point
  92. EndWhile
  93.  
  94. Finish:
  95. Gfx RestoreMode 0               ;Restore Gfx to previous modes
  96. Wait 30000                      ;Wait for 10 minutes to show off the graph
  97. End
  98.  
  99. Label Complain
  100. con cls                       ;show usage message
  101. con style 33;1
  102. con echo "Plot.  A Scripit script.\n"
  103. con style 0
  104. con echo "Draw a function of form y = f(x) where all arguments are from the command"
  105. con echo "line in the following format:"
  106. con echo "function, startx, endx, scalex, scaley"
  107. con echo "function is in the format  f(#x)  ex:  #x^2-4*#x for x^2-4x\n"
  108. con style 2
  109. con echo "By Brian J. Bartlett (CIS 72037,570)" " "
  110. con style 0
  111. ;; In the following lines we're using ~ instead of " since we need to actually
  112. ;; print the double quote character.
  113. con text ~Try running it like this:\n\tScripit ~ $scriptname ~ "func" 0 20 1 1\n\n~
  114. con text ~Or, to use the default formula:\n\tScripit ~ $scriptname ~ "" 0 20 1 1\n\n~
  115. con text ~To see a debug of the process try:\n\tScripit >ram:dump -d ~ $scriptname ~ "" 0 20 1 1\n~
  116. con echo "\tthen have a look at ram:dump.\n"
  117. con echo "\tUSE CONTROL-LEFT MOUSE BUTTON TO BREAK OUT!!!"
  118. con echo "\tunless you like waiting for 10 minutes for the script to end.\n"
  119. Return
  120.